<template>
  <VDialog @close="handleClose" @save="save" :loading="loading">
    <template #content>
      <el-input
        v-model="textarea"
        :rows="4"
        type="textarea"
        placeholder="请输入"
      />
    </template>
  </VDialog>
</template>
<script setup>
import { ElMessage } from "element-plus";
import { computed } from "vue";
import { review } from "./api";
const props = defineProps({
  remarkData: { type: Object, default: () => {} },
  method: { type: String, default: "post" },
  url: { type: String, default: "" },
  data: { type: String, default: "" },
});

const { url, method, remarkData } = toRefs(props);
const params = computed(() => remarkData.value);
const textarea = ref("");
const emit = defineEmits(["update:modelValue", "close", "refresh"]);
const loading = ref(false);
watch(
  () => props.data,
  (val) => {
    textarea.value = val;
  }
);
const handleClose = async (refresh) => {
  textarea.value = null;
  emit("update:modelValue", false);
  emit("close");
  if (refresh) emit("refresh");
};
const save = async () => {
  let obj = Object.assign({}, params.value, { remark: textarea.value });
  const { code, message } = await review(url.value, obj, method.value);
  if (code !== 200) {
    ElMessage.warning(message);
    return;
  }
  ElMessage.success("修改成功!");
  handleClose(true);
};
</script>
